using System;
using System.Collections.Generic;
using System.Text;

namespace Web.Core
{
    public class ConvertType
    {
        public static int ToInt(object o)
        {
            try
            {
                return int.Parse(o.ToString());
            }
            catch
            {

            }
            return 0;
        }  

        public static float ToFloat(object o)
        {
            try
            {
                return float.Parse(o.ToString());
            }
            catch
            {

            }
            return 0;
        }

        public static long ToLong(object o)
        {
            try
            {
                return long.Parse(o.ToString());
            }
            catch
            {

            }
            return 0;
        }
        public static double ToDouble(object o)
        {
            try
            {
                return double.Parse(o.ToString());
            }
            catch
            {

            }
            return 0;
        }


        public static Boolean ToBool(object o)
        {
            try
            {
                return bool.Parse(o.ToString());
            }
            catch
            {

            }
            return false;
        }

        public static string ToDateTime(object o)
        {
            try
            {
                DateTime date = DateTime.Parse(o.ToString());
                return date.Month + "/" + date.Day + "/" + date.Year + " " + date.Hour + ":" + date.Minute + ":" + date.Second;
            }
            catch
            {

            }
            return "";
        }

        public static string ToDate(object o)
        {
            try
            {
                DateTime date = DateTime.Parse(o.ToString());
                return date.Month + "/" + date.Day + "/" + date.Year;
            }
            catch
            {

            }
            return "";
        }

        public static int BitToInt(object o)
        {
            try
            {
                if (bool.Parse(o.ToString()) == true)
                    return 1;
                else
                    return 0;
            }
            catch
            {

            }
            return 0;
        }
    }
}
